<?php


// This module needs cleaning up -steinn @ oct 2006
function get_include_contents($filename)
{
	if (is_file($filename))
	{
		ob_start();
		include $filename;
		$contents = ob_get_contents();
		ob_end_clean();
		return $contents;
	}
	return false;
}

class block_presence extends block_base
{
	function init()
	{
		global $CFG;
		$this->title = get_string('blockname', 'block_presence');
		$this->version = 2006072000;

		//XXX: MESSY HAX
		$this->basepath = dirname(__FILE__) . "/";
		$this->baseurl = $CFG->wwwroot."/blocks/presence/";
		set_config("baseurl",$this->baseurl);
		set_config("basepath",$this->basepath);
		set_config("ajwrap_path",$this->baseurl."jwc/pml.php");
		set_config("saver_path",$this->baseurl."jwc/saver.php");
	}

	function get_content()
	{
		global $CFG, $USER, $COURSE;
		if ($this->content !== NULL) {
			return $this->content;
		}

		#print "<!--";
		#print_r($USER);
		#print_r($COURSE);
		#print "-->";

		$this->content = new stdClass;
		// this is quite messy (the index.html is actually a php file!)
		$this->content->text = '';
		$this->content->footer = get_include_contents($this->basepath . 'jwc/index.html');
		
		//if ($CFG->cp_wb_link)
		//	$this->content->footer .= '<br /><a href="javascript:void(0);" onclick="openpopup(\'/mod/cwhiteboard/new.php\',\'cwhiteboard\',\'menubar=0,location=0,width=650,height=520,resizable\', 0)" id="wblink">Start whiteboard</a>';

		return $this->content;
	}

	function specialization()
	{
		global $CFG;
		$this->title = $CFG->title;
	}

	function has_config()
	{
		return true;
	}

	function config_save($data)
	{
		// Default behavior: save all variables as $CFG properties
		foreach ($data as $name => $value)
		{
			set_config($name, $value);
		}
		return true;
	}
}
?>
